package com.badibadi.fragment;

import com.badibadi.uniclubber.R;

import android.os.Bundle;
import android.os.Handler;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;

public class AfterLandingMyHomePageMessageFragment extends BaseAppFragment {

	TabHost tabhost;
	private FragmentManager manager;
	private int add_in = 0;

	AfterLandingMessageItem00 aItem00;
	AfterLandingMessageItem01 aItem01;
	AfterLandingMessageItem02 aItem02;
	AfterLandingMessageItem03 aItem03;
	AfterLandingMessageItem04 aItem04;
	AfterLandingMessageItem05 aItem05;
	AfterLandingMessageItem06 aItem06;

	@Override
	public void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		manager = getFragmentManager();
		aItem00 = new AfterLandingMessageItem00();
		aItem01 = new AfterLandingMessageItem01();
		aItem02 = new AfterLandingMessageItem02();
		aItem03 = new AfterLandingMessageItem03();
		aItem04 = new AfterLandingMessageItem04();
		aItem05 = new AfterLandingMessageItem05();
		aItem06 = new AfterLandingMessageItem06();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(
				R.layout.fragment_after_landing_message_me, null);
		initFragment();
		settingTabHost(view);
		return view;
	}

	private void initFragment() {
		// TODO Auto-generated method stub
		FragmentTransaction transaction = manager.beginTransaction();
		transaction.replace(R.id.fragment_message_layout, aItem00);
		transaction.commit();
		add_in = 0;

	}

	private void settingTabHost(View view) {
		tabhost = (TabHost) view
				.findViewById(R.id.fragment_after_message_me_tabhost);

		tabhost.setup();
		tabhost.addTab(tabhost
				.newTabSpec("message_me one")
				.setIndicator(getResources().getString(R.string.Pair),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab1));
		tabhost.addTab(tabhost
				.newTabSpec("message_me two")
				.setIndicator(getResources().getString(R.string.SetUp),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab2));
		tabhost.addTab(tabhost
				.newTabSpec("message_me three")
				.setIndicator(getResources().getString(R.string.Praise),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab3));
		tabhost.addTab(tabhost
				.newTabSpec("message_me four")
				.setIndicator(getResources().getString(R.string.Comment),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab4));
		tabhost.addTab(tabhost
				.newTabSpec("message_me five")
				.setIndicator(getResources().getString(R.string.Share),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab5));
		tabhost.addTab(tabhost
				.newTabSpec("message_me six")
				.setIndicator(getResources().getString(R.string.Collect),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab6));
		tabhost.addTab(tabhost
				.newTabSpec("message_me seven")
				.setIndicator(getResources().getString(R.string.Uploading),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab7));

		TabWidget tabWidget = tabhost.getTabWidget();
		// 注意这个就是改变Tabhost默认样式的地方，一定将这部分代码放在上面这段代码的下面，不然样式改变不了
		for (int i = 0; i < tabWidget.getChildCount(); i++) {
			Bundle args = getArguments();
			// if(args!=null)
			// {
			float a = args.getFloat("SCREENW");
			// }
			// 修改Tabhost高度和宽度
			// tabWidget.getChildAt(i).getLayoutParams().height = (int) a;
			tabWidget.getChildAt(i).getLayoutParams().width = (int) a / 7;
			// 修改显示字体大小
			TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(
					android.R.id.title);
			tv.setTextSize(7);
			tv.setTextColor(getActivity().getResources().getColor(
					R.color.black_0));
		}
		tabhost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
			@Override
			public void onTabChanged(String arg0) {
				// TODO Auto-generated method stub
				FragmentTransaction transaction = manager.beginTransaction();
				switch (tabhost.getCurrentTab()) {
				case 0:
					if (add_in != 0) {
						transaction.replace(R.id.fragment_message_layout,
								aItem00);
						transaction.commit();
						add_in = 0;
					}
					break;
				case 1:
					if (add_in != 1) {
						transaction.replace(R.id.fragment_message_layout,
								aItem01);
						transaction.commit();
						add_in = 1;
					}
					break;
				case 2:
					if (add_in != 2) {
						transaction.replace(R.id.fragment_message_layout,
								aItem02);
						transaction.commit();
						add_in = 2;
					}
					break;
				case 3:
					if (add_in != 3) {
						transaction.replace(R.id.fragment_message_layout,
								aItem03);
						transaction.commit();
						add_in = 3;
					}
					break;
				case 4:
					if (add_in != 4) {
						transaction.replace(R.id.fragment_message_layout,
								aItem04);
						transaction.commit();
						add_in = 4;
					}
					break;
				case 5:
					if (add_in != 5) {
						transaction.replace(R.id.fragment_message_layout,
								aItem05);
						transaction.commit();
						add_in = 5;
					}
					break;
				case 6:
					if (add_in != 6) {
						transaction.replace(R.id.fragment_message_layout,
								aItem06);
						transaction.commit();
						add_in = 6;
					}
					break;
				}
			}
		});

	}
}
